/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pacote;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.persistence.TypedQuery;

/**
 *
 * @author Pardall
 */
@Entity
@Table(name = "vendas", catalog = "ecom", schema = "")
@NamedQueries({
    @NamedQuery(name = "Vendas.findAll", query = "SELECT v FROM Vendas v"),
    @NamedQuery(name = "Vendas.findById", query = "SELECT v FROM Vendas v WHERE v.id = :id"),
    @NamedQuery(name = "Vendas.findByIdProd", query = "SELECT v FROM Vendas v WHERE v.idProd = :idProd"),
    @NamedQuery(name = "Vendas.findByIdUser", query = "SELECT v FROM Vendas v WHERE v.idUser = :idUser"),
    @NamedQuery(name = "Vendas.findByDatap", query = "SELECT v FROM Vendas v WHERE v.datap = :datap"),
    @NamedQuery(name = "Vendas.findBySituacao", query = "SELECT v FROM Vendas v WHERE v.situacao = :situacao")})
public class Vendas implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Short id;
    @Basic(optional = false)
    @Column(name = "id_prod")
    private String idProd;
    @Basic(optional = false)
    @Column(name = "id_user")
    private short idUser;
    @Basic(optional = false)
    @Column(name = "datap")
    @Temporal(TemporalType.TIMESTAMP)
    private Date datap;
    @Basic(optional = false)
    @Column(name = "situacao")
    private boolean situacao;
    @Transient
    private List<Itemsvendas> items;

    public Vendas() {
    }

    public Vendas(Short id) {
        this.id = id;
    }

    public Vendas(Short id, String idProd, short idUser, Date datap, boolean situacao) {
        this.id = id;
        this.idProd = idProd;
        this.idUser = idUser;
        this.datap = datap;
        this.situacao = situacao;
    }

        /**
     * @return the items
     */
    public List<Itemsvendas> getItems(EntityManager exm) {
        if (items == null){
            TypedQuery<Itemsvendas> query = exm.createNamedQuery("Itemsvendas.findByIdVenda", Itemsvendas.class);
            query.setParameter("idVenda", id);
            items = query.getResultList();
        }
        return items;
    }

    public Itemsvendas getItem(int index){
        return items.get(index);
    }

    /**
     * @param items the items to set
     */
    public void setItems(List<Itemsvendas> items) {
        this.items = items;
    }

    public Short getId() {
        return id;
    }

    public void setId(Short id) {
        this.id = id;
    }

    public String getIdProd() {
        return idProd;
    }

    public void setIdProd(String idProd) {
        this.idProd = idProd;
    }

    public short getIdUser() {
        return idUser;
    }

    public void setIdUser(short idUser) {
        this.idUser = idUser;
    }

    public Date getDatap() {
        return datap;
    }

    public void setDatap(Date datap) {
        this.datap = datap;
    }

    public boolean getSituacao() {
        return situacao;
    }

    public void setSituacao(boolean situacao) {
        this.situacao = situacao;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Vendas)) {
            return false;
        }
        Vendas other = (Vendas) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "pacote.Vendas[id=" + id + "]";
    }
}
